<?php declare(strict_types=1);
/**
 * @author      guosir
 * @copyright   2023-2025 owner
 **/

namespace Srv\Apps\Apis\User;

use Srv\Apps\Apis\Log\Ctl\LogCtl;
use Srv\Apps\Apis\User\Ctl\UserCtl;
use Srv\Apps\Proto\DTO\User\RechargeActRecordListDTO;
use Srv\Apps\Proto\DTO\User\UserBillListDTO;
use Srv\Apps\Proto\DTO\User\UserBindListDTO;
use Srv\Apps\Proto\DTO\User\UserFullListDTO;
use Srv\Apps\Proto\DTO\User\UserIdDTO;
use Srv\Apps\Proto\DTO\User\UserInfoEditDTO;
use Srv\Apps\Proto\DTO\User\UserOnlineListDTO;
use Srv\Apps\Proto\DTO\User\UserSkitChasingListDTO;
use Srv\Apps\Proto\DTO\User\UserSkitUnlockListDTO;
use Srv\Apps\Proto\DTO\User\UserSkitWatchListDTO;
use Srv\Apps\Proto\DTO\User\UserSkitPlayListDTO;
use Srv\Apps\Proto\DTO\User\UserTaskRewardListDTO;
use Srv\Apps\Proto\DTO\User\UserTokenListDTO;
use Srv\Apps\Proto\Enum\ErrCodeEnum;
use Srv\Apps\Proto\Enum\LangKeyEnum;
use Srv\Apps\Proto\Enum\Log\LogResultEnum;
use Srv\Apps\Proto\VO\User\RechargeActRecordListVO;
use Srv\Apps\Proto\VO\User\UserBillListVO;
use Srv\Apps\Proto\VO\User\UserBindListVO;
use Srv\Apps\Proto\VO\User\UserFullListVO;
use Srv\Apps\Proto\VO\User\UserFullVO;
use Srv\Apps\Proto\VO\User\UserOnlineListVO;
use Srv\Apps\Proto\VO\User\UserSkitChasingListVO;
use Srv\Apps\Proto\VO\User\UserSkitUnlockListVO;
use Srv\Apps\Proto\VO\User\UserSkitWatchListVO;
use Srv\Apps\Proto\VO\User\UserSkitPlayListVO;
use Srv\Apps\Proto\VO\User\UserTaskRewardListVO;
use Srv\Apps\Proto\VO\User\UserTokenListVO;
use Srv\Libs\ConfModel\RouteConfData;
use Srv\Libs\Frame\ActionAbstract;
use Srv\Libs\Frame\DTOAbstract;
use Srv\Libs\Frame\Lang;
use Srv\Libs\Frame\Page;
use Srv\Libs\Frame\ResponseData;
use Srv\Libs\Frame\VOAbstract;

final class UserAct extends ActionAbstract
{
    /**
     * @url /user/info/list
     * @auth userInfoList
     * @req Srv.Apps.Proto.DTO.User.UserFullListDTO
     * @rsp Srv.Apps.Proto.VO.User.UserFullListVO
     * 用户列表
     */
    public function getUserInfoList(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        if(!($DTOClass instanceof UserFullListDTO) || !($VOClass instanceof UserFullListVO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $Page                   = new Page();
        $currPage               = max(1, $DTOClass->getCurrPage());
        $pageSize               = $DTOClass->getPageSize() < 1 ? 12 : $DTOClass->getPageSize();
        $Page->init(0, $pageSize, $currPage);
        $whereData              = $RouteConfData->getParamsResData($DTOClass);
        $VOClass                = UserCtl::tag()->getUserFullList($Page, $whereData);
        return ResponseData::rspSuccAuto('', $VOClass);
    }

    /**
     * @url /user/info/detail
     * @auth userInfoDetail
     * @req Srv.Apps.Proto.DTO.User.UserIdDTO
     * @rsp Srv.Apps.Proto.VO.User.UserFullVO
     * 用户详情
     */
    public function getUserInfoDetail(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        unset($RouteConfData);
        if(!($DTOClass instanceof UserIdDTO) || !($VOClass instanceof UserFullVO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $userId         = intval($DTOClass->getUserId());
        $VOClass        = UserCtl::tag()->getUserInfoDetail($userId);
        return ResponseData::rspSuccAuto('', $VOClass);
    }

    /**
     * @url /user/info/edit
     * @auth userInfoEdit
     * @req Srv.Apps.Proto.DTO.User.UserInfoEditDTO
     * 用户信息编辑
     */
    public function userEdit(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        unset($VOClass);
        if(!($DTOClass instanceof UserInfoEditDTO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $userId         = intval($DTOClass->getUserId());
        $setData        = $RouteConfData->getParamsResData($DTOClass);
        $UserCtl        = UserCtl::tag();
        $LogCtl         = LogCtl::tag();
        $userSrc        = $UserCtl->getUserSrc($userId);
        if(!isset($userSrc['user_id'])) {
            $errMsg     = '用户信息不存在';
            $logData    = $setData;
            $LogCtl->logAdd(LogCtl::USER_EDIT, LogResultEnum::LOG_RESULT_FAIL, $errMsg, $logData);
            return ResponseData::rspErrAuto(ErrCodeEnum::ERR_FAIL, Lang::getString(LangKeyEnum::_LANG_FAILED));
        }
        $result         = $UserCtl->userEdit($userId, $setData);
        $logData        = ['new' => $setData, 'old' => $userSrc];
        if(!$result) {
            $errMsg     = '用户信息编辑失败';
            $LogCtl->logAdd(LogCtl::USER_EDIT, LogResultEnum::LOG_RESULT_FAIL, $errMsg, $logData);
            return ResponseData::rspErrAuto(ErrCodeEnum::ERR_FAIL, Lang::getString(LangKeyEnum::_LANG_FAILED));
        }
        $errMsg         = '用户信息编辑成功';
        $LogCtl->logAdd(LogCtl::USER_EDIT, LogResultEnum::LOG_RESULT_SUCCESS, $errMsg, $logData);
        return ResponseData::rspSuccAuto('', null);
    }

    /**
     * @url /user/bind/list
     * @auth userBindList
     * @req Srv.Apps.Proto.DTO.User.UserBindListDTO
     * @rsp Srv.Apps.Proto.VO.User.UserBindListVO
     * 用户绑定记录
     */
    public function getUserBindList(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        if(!($DTOClass instanceof UserBindListDTO) || !($VOClass instanceof UserBindListVO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        if(!$RouteConfData->isSetParam(UserBindListDTO::_userId)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $Page                   = new Page();
        $currPage               = max(1, $DTOClass->getCurrPage());
        $pageSize               = $DTOClass->getPageSize() < 1 ? 12 : $DTOClass->getPageSize();
        $Page->init(0, $pageSize, $currPage);
        $whereData              = $RouteConfData->getParamsResData($DTOClass);
        $VOClass                = UserCtl::tag()->getUserBindList($Page, $whereData);
        return ResponseData::rspSuccAuto('', $VOClass);
    }

    /**
     * @url /user/token/list
     * @auth userTokenList
     * @req Srv.Apps.Proto.DTO.User.UserTokenListDTO
     * @rsp Srv.Apps.Proto.VO.User.UserTokenListVO
     * 用户令牌记录
     */
    public function getUserTokenList(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        if(!($DTOClass instanceof UserTokenListDTO) || !($VOClass instanceof UserTokenListVO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        if(!$RouteConfData->isSetParam(UserTokenListDTO::_userId)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $Page                   = new Page();
        $currPage               = max(1, $DTOClass->getCurrPage());
        $pageSize               = $DTOClass->getPageSize() < 1 ? 12 : $DTOClass->getPageSize();
        $Page->init(0, $pageSize, $currPage);
        $whereData              = $RouteConfData->getParamsResData($DTOClass);
        $VOClass                = UserCtl::tag()->getUserTokenList($Page, $whereData);
        return ResponseData::rspSuccAuto('', $VOClass);
    }

    /**
     * @url /user/skit/unlock/list
     * @auth userSkitUnlockList
     * @req Srv.Apps.Proto.DTO.User.UserSkitUnlockListDTO
     * @rsp Srv.Apps.Proto.VO.User.UserSkitUnlockListVO
     * 用户购买剧集列表
     */
    public function getUserSkitUnlockList(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        if(!($DTOClass instanceof UserSkitUnlockListDTO) || !($VOClass instanceof UserSkitUnlockListVO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        if(!$RouteConfData->isSetParam(UserSkitUnlockListDTO::_userId)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $Page                   = new Page();
        $currPage               = max(1, $DTOClass->getCurrPage());
        $pageSize               = $DTOClass->getPageSize() < 1 ? 12 : $DTOClass->getPageSize();
        $Page->init(0, $pageSize, $currPage);
        $whereData              = $RouteConfData->getParamsResData($DTOClass);
        $VOClass                = UserCtl::tag()->getUserSkitUnlockList($Page, $whereData);
        return ResponseData::rspSuccAuto('', $VOClass);
    }

    /**
     * @url /user/bill/list
     * @auth userBillList
     * @req Srv.Apps.Proto.DTO.User.UserBillListDTO
     * @rsp Srv.Apps.Proto.VO.User.UserBillListVO
     * 用户账单明细列表
     */
    public function getUserBillList(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        if(!($DTOClass instanceof UserBillListDTO) || !($VOClass instanceof UserBillListVO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        if(!$RouteConfData->isSetParam(UserSkitUnlockListDTO::_userId)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $Page                   = new Page();
        $currPage               = max(1, $DTOClass->getCurrPage());
        $pageSize               = $DTOClass->getPageSize() < 1 ? 12 : $DTOClass->getPageSize();
        $Page->init(0, $pageSize, $currPage);
        $whereData              = $RouteConfData->getParamsResData($DTOClass);
        $VOClass                = UserCtl::tag()->getUserBillList($Page, $whereData);
        return ResponseData::rspSuccAuto('', $VOClass);
    }

    /**
     * @url /user/skit/watch/list
     * @auth userSkitWatchList
     * @req Srv.Apps.Proto.DTO.User.UserSkitWatchListDTO
     * @rsp Srv.Apps.Proto.VO.User.UserSkitWatchListVO
     * 用户观看剧集列表
     */
    public function getUserSkitWatchList(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        if(!($DTOClass instanceof UserSkitWatchListDTO) || !($VOClass instanceof UserSkitWatchListVO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        if(!$RouteConfData->isSetParam(UserSkitWatchListDTO::_userId)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $Page                   = new Page();
        $currPage               = max(1, $DTOClass->getCurrPage());
        $pageSize               = $DTOClass->getPageSize() < 1 ? 12 : $DTOClass->getPageSize();
        $Page->init(0, $pageSize, $currPage);
        $whereData              = $RouteConfData->getParamsResData($DTOClass);
        $VOClass                = UserCtl::tag()->getUserSkitWatchList($Page, $whereData);
        return ResponseData::rspSuccAuto('', $VOClass);
    }

    /**
     * @url /user/task/reward/list
     * @auth userTaskRewardList
     * @req Srv.Apps.Proto.DTO.User.UserTaskRewardListDTO
     * @rsp Srv.Apps.Proto.VO.User.UserTaskRewardListVO
     * 用户任务奖励列表
     */
    public function getUserTaskRewardList(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        if(!($DTOClass instanceof UserTaskRewardListDTO) || !($VOClass instanceof UserTaskRewardListVO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        if(!$RouteConfData->isSetParam(UserTaskRewardListDTO::_userId)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $Page                   = new Page();
        $currPage               = max(1, $DTOClass->getCurrPage());
        $pageSize               = $DTOClass->getPageSize() < 1 ? 12 : $DTOClass->getPageSize();
        $Page->init(0, $pageSize, $currPage);
        $whereData              = $RouteConfData->getParamsResData($DTOClass);
        $VOClass                = UserCtl::tag()->getUserTaskRewardList($Page, $whereData);
        return ResponseData::rspSuccAuto('', $VOClass);
    }

    /**
     * @url /user/skit/play/list
     * @auth userSkitPlayList
     * @req Srv.Apps.Proto.DTO.User.UserSkitPlayListDTO
     * @rsp Srv.Apps.Proto.VO.User.UserSkitPlayListVO
     * 用户播放记录列表
     */
    public function getUserSkitPlayList(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        if(!($DTOClass instanceof UserSkitPlayListDTO) || !($VOClass instanceof UserSkitPlayListVO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        if(!$RouteConfData->isSetParam(UserSkitPlayListDTO::_userId)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $Page                   = new Page();
        $currPage               = max(1, $DTOClass->getCurrPage());
        $pageSize               = $DTOClass->getPageSize() < 1 ? 12 : $DTOClass->getPageSize();
        $Page->init(0, $pageSize, $currPage);
        $whereData              = $RouteConfData->getParamsResData($DTOClass);
        $VOClass                = UserCtl::tag()->getUserSkitPlayList($Page, $whereData);
        return ResponseData::rspSuccAuto('', $VOClass);
    }

    /**
     * @url /user/skit/chasing/list
     * @auth userSkitChasingList
     * @req Srv.Apps.Proto.DTO.User.UserSkitChasingListDTO
     * @rsp Srv.Apps.Proto.VO.User.UserSkitChasingListVO
     * 用户追剧记录列表
     */
    public function getUserSkitChasingList(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        if(!($DTOClass instanceof UserSkitChasingListDTO) || !($VOClass instanceof UserSkitChasingListVO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        if(!$RouteConfData->isSetParam(UserSkitChasingListDTO::_userId)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $Page                   = new Page();
        $currPage               = max(1, $DTOClass->getCurrPage());
        $pageSize               = $DTOClass->getPageSize() < 1 ? 12 : $DTOClass->getPageSize();
        $Page->init(0, $pageSize, $currPage);
        $whereData              = $RouteConfData->getParamsResData($DTOClass);
        $VOClass                = UserCtl::tag()->getUserSkitChasingList($Page, $whereData);
        return ResponseData::rspSuccAuto('', $VOClass);
    }

    /**
     * @url /user/online/list
     * @auth userOnlineList
     * @req Srv.Apps.Proto.DTO.User.UserOnlineListDTO
     * @rsp Srv.Apps.Proto.VO.User.UserOnlineListVO
     * 用户在线记录列表
     */
    public function getUserOnlineList(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        if(!($DTOClass instanceof UserOnlineListDTO) || !($VOClass instanceof UserOnlineListVO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        if(!$RouteConfData->isSetParam(UserOnlineListDTO::_userId)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $Page                   = new Page();
        $currPage               = max(1, $DTOClass->getCurrPage());
        $pageSize               = $DTOClass->getPageSize() < 1 ? 12 : $DTOClass->getPageSize();
        $Page->init(0, $pageSize, $currPage);
        $whereData              = $RouteConfData->getParamsResData($DTOClass);
        $VOClass                = UserCtl::tag()->getUserOnlineList($Page, $whereData);
        return ResponseData::rspSuccAuto('', $VOClass);
    }

    /**
     * @url /user/recharge/act/list
     * @auth userRechargeActList
     * @req Srv.Apps.Proto.DTO.User.RechargeActRecordListDTO
     * @rsp Srv.Apps.Proto.VO.User.RechargeActRecordListVO
     * 用户充值活动记录列表
     */
    public function getUserRechargeActList(RouteConfData $RouteConfData, ?DTOAbstract $DTOClass, ?VOAbstract $VOClass):bool
    {
        if(!($DTOClass instanceof RechargeActRecordListDTO) || !($VOClass instanceof RechargeActRecordListVO)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        if(!$RouteConfData->isSetParam(UserOnlineListDTO::_userId)) return ResponseData::rspErrAuto(ErrCodeEnum::ERR_SYS_PARAMS_ERROR, Lang::get(LangKeyEnum::LANG_SYS_PARAMS_ERROR));
        $Page                   = new Page();
        $currPage               = max(1, $DTOClass->getCurrPage());
        $pageSize               = $DTOClass->getPageSize() < 1 ? 12 : $DTOClass->getPageSize();
        $Page->init(0, $pageSize, $currPage);
        $whereData              = $RouteConfData->getParamsResData($DTOClass);
        $VOClass                = UserCtl::tag()->getUserRechargeActList($Page, $whereData);
        return ResponseData::rspSuccAuto('', $VOClass);
    }
}